package com.woniuxy.dr_mall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.dr_mall.entity.DrSpec;
import com.woniuxy.dr_mall.mapper.DrSpecMapper;
import com.woniuxy.dr_mall.mapper.DrSpecPriceMapper;
import com.woniuxy.dr_mall.mapper.DrSpecValMapper;
import com.woniuxy.dr_mall.service.IDrSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张哲轩
 * @since 2021-08-11
 */
@Service
public class DrSpecServiceImpl extends ServiceImpl<DrSpecMapper, DrSpec> implements IDrSpecService {

    @Autowired
    private DrSpecMapper specMapper;

    @Autowired
    private DrSpecPriceMapper specPriceMapper;

    @Autowired
    private DrSpecValMapper specValMapper;


    @Override
    public List<DrSpec> getSpecs(int productId) {
        return specMapper.getSpecs(productId);
    }

    @Override
    public List<DrSpec> getNotNullSpecs(int productId) {
        List<DrSpec> specs = specMapper.getSpecs(productId);
        for(DrSpec spec:specs){
            spec.getSpecVals().clear();
            for (Integer valId : specPriceMapper.getAllValByColumn(spec,productId)) {
                spec.getSpecVals().add( specValMapper.selectById(valId));
            }
        }

        return specs;
    }

    @Override
    public List<DrSpec> getByCategory(int categoryId) {
        return specMapper.getByCategory(categoryId);
    }
}
